package com.bw.controller;

import com.bw.entity.User;
import com.bw.mapper.UserMapper;
import org.spring.kun.common.JwtUtils;
import org.spring.kun.common.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ListController {

    @Autowired
    UserMapper userMapper;

    @RequestMapping("/list.do")
    public String list(HttpServletRequest request,Model model){
        // 获取当前登录用户   从request中获取cookie  从cookie中获取token令牌，  再解密token得到用户

        User userFromRequest = TokenUtils.getLoginUserFromRequest(request, User.class);

        model.addAttribute("name",userFromRequest.getName());

        return "list";

    }
}
